package com.briup.myblog.utils;

import com.briup.myblog.exception.CustomerException;

import javax.servlet.http.HttpServletRequest;

public class GetToken {
    public static String getToken(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        if(token == null){
            throw new CustomerException("用户未登录，请重新登录");
        }
        //请求头中提供了token值，进行验证
        try{
            JwtUtil.checkSign(token);
        }catch (Exception e){
            e.printStackTrace();//打印错误信息，方便调试代码
            throw new CustomerException("token无效，用户重新登录");
        }
        return token;
    }
}
